#include "rpc/rpc_util.h"
#include "rpc/connection.h"
#include "include/rpc_helper.h"

namespace urpc {

void SenderClosure::Run() {
  // fixme: should send once...
  std::string tmp = msg_->SerializeAsString();
  RpcHeader bhs = { 0 };
  bhs.magic_num = URPC_MAGIC;
  bhs.length = tmp.size();
  bhs.id = id_;
//  bhs.func_id = 0;

  conn_->Send((const u_char*) &bhs, HEADER_LENGTH);
  conn_->Send((const u_char*) tmp.c_str(), tmp.size());
}

AutoRunner::~AutoRunner() {
  if (closure_ != NULL) {
    closure_->Run();
  }
}

}
